package com.redpill.linpro.integration.stub;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.redpill.linpro.integration.Account;
import com.redpill.linpro.integration.AccountRepository;
import com.redpill.linpro.integration.Amount;

/**
 * All accounts have 100 in balance.
 * 
 * Account number "INVALID" will throw exception.
 * 
 * @author Espen Berntsen
 * 
 */
@Repository
public class AccountRepositoryStub implements AccountRepository {

	private int counter = 0;

	private final Amount AMOUNT = new Amount(100);
	
	private final Logger logger = LoggerFactory
			.getLogger(AccountRepositoryStub.class);

	
	@Override
	public void updateBalance(Amount balance, Account account) {
		counter++;		
	}

	@Override
	public Amount getBalance(Account account) {
		counter++;
		logger.debug("{} has {} in balance.", new Object[] { account, AMOUNT });
		return AMOUNT;
	}
	
	public int getCounter() {
		return counter;
	}

	/**
	 * @return true unless {@link Account#getAccountNumber()} is equal to INVALID.
	 */
	@Override
	public boolean isAccountExisting(Account account) {
		return (account.getAccountNumber().equals("INVALID") ? false : true);
	}
}
